package test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * @author sunzhuokun
 * @date 14:05 2024/5/13
 * @description 解密犯罪时间
 */
public class CrimeTimeDecrypting2_解密犯罪时间 {

    private static final String TIME_REG = "(([01][0-9])|([2][0-3]))[0-5][0-9]";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String input = sc.nextLine();
        String[] inputArr = input.split(":");
        String hour = inputArr[0];
        String minute = inputArr[1];
        System.out.println(reasoning(hour, minute));
    }

    private static String reasoning(String hour, String minute) {
        List<Character> arr = new ArrayList<>();
        for (char c : hour.toCharArray()) {
            arr.add(c);
        }
        for (char c : minute.toCharArray()) {
            arr.add(c);
        }
        // 去重
        arr = arr.stream().distinct().collect(Collectors.toList());
        List<String> res = new ArrayList<>();
        dfs(arr, new LinkedList<String>(), res);
        res = res.stream().sorted().collect(Collectors.toList());
        int index = res.indexOf(hour + minute);
        String resTime = "";
        if (index == res.size() - 1) {
            resTime = res.get(0);
        } else {
            resTime = res.get(index + 1);
        }
        List<String> resList = Arrays.stream(resTime.split("")).collect(Collectors.toList());
        String st = resList.get(1) + ":";
        resList.set(1, st);

        return String.join("", resList);
    }

    private static void dfs(List<Character> arr, LinkedList<String> pathList,  List<String> res) {
        if (pathList.size() == 4) {
            String timeStr = String.join("", pathList);
            if (timeStr.matches(TIME_REG)) {
                res.add(timeStr);
            }
            return;
        }

        // 构建时间组合，从尾部一个个添加元素，判断是否合法，再从尾部逐个去除，添加下一个
        for (int i = 0; i < arr.size(); i++) {
            pathList.addLast(arr.get(i).toString());
            dfs(arr, pathList, res);
            pathList.pollLast();
        }
    }


}
